package XMLread;

import java.util.StringTokenizer;

import routeFunctions.Loc;

/**
 * 
 *This class specifies a building that is generated when parsing a building csv file.
 *
 */
public class BuildingCSV {
	private Loc[] shape;
	private String name;
	private String shortName;
	private int buildingid;
	
	/**
	 * Constructs a building from parsed data from a CSV file
	 * 
	 * @param shapePoints string containing all of the latitudes and longitudes that make up the outline of this building
	 * @param name the name of this building
	 * @param shortName the short name of this building
	 * @param buildingid the building ID corresponding to this building
	 */
	public BuildingCSV(String shapePoints, String name, String shortName, String buildingid){
		setShape(shapePoints);
		setName(name);
		setshortName(shortName);
		setBuildingid(buildingid);
	}
	
	/**
	 *  @return returns an array of Locations that can be used to add an overlay of this building's shape to a map view
	 */
	public Loc[] getShape() {
		return shape;
	}
	
	/**
	 * Takes a string that lists outline points of a building. parses this string and adds each point to the shape[] of the building
	 * @param shapePoints string of longitudes and latitudes
	 */
	public void setShape(String shapePoints) {
		StringTokenizer st = new StringTokenizer(shapePoints, "|");
		shape = new Loc[st.countTokens()];
		int i = 0;
		
		//process each edge
		while(st.hasMoreTokens()){
			
			//split edge into lat and long
			StringTokenizer edge = new StringTokenizer(st.nextToken(), " ");
			double lon = Double.valueOf(edge.nextToken());
			double lat = Double.valueOf(edge.nextToken());
			shape[i] = new Loc(lat, lon);
			i++;
		}
	}
	
	/**
	 * @return the name of the building
	 */
	public String getName() {
		return name;
	}
	
	/**
	 * @param naem the name to set to this building
	 */
	public void setName(String name) {
		this.name = name;
	}
	
	/**
	 * @return the short name of the building
	 */
	public String getshortName() {
		return shortName;
	}
	
	/**
	 * @param shortName the short name to set to this building
	 */
	public void setshortName(String shortName) {
		this.shortName = shortName;
	}
	
	/**
	 * @return the ID of the building
	 */
	public int getBuildingid() {
		return buildingid;
	}
	
	/**
	 * @param id the id to set to this building
	 */
	public void setBuildingid(String id) {
		buildingid = Integer.valueOf(id);
	}
}
